<template>
	<view class="ys">
		<view class="form">
			<uni-section title="选择城市房间" type="line" padding>
				<uni-data-picker placeholder="请选择地区" popup-title="请选择所在地区" :localdata="dataTree" v-model="city"
					@change="onchange">
				</uni-data-picker>
			</uni-section>
		</view>
		<button class="btn" @click="chooseArea" :loading="loading" :disabled="loading">提交</button>
	</view>
</template>

<script>
	import {
		getArea
	} from "@/api/api.js"
	import {
		chooseArea
	} from "@/api/user.js"
	export default {
		data() {
			return {
				city: [],
				dataTree: [],
				loading: false
			}
		},
		onLoad() {
			this.getArea()
		},
		methods: {
			onchange(e) {
				console.log(e);
			},
			getArea() {
				getArea().then(res => {
					if (res.code == 0) {
						this.dataTree = res.data
					}
				})
			},
			chooseArea() {
				let that = this
				if (!this.city) {
					return uni.$showMsg('请选择城市')
				}
				that.loading = true
				chooseArea({
					city: this.city
				}).then(res => {
					uni.$showMsg(res.msg)
					if (res.code == 0) {
						setTimeout(() => {
							uni.switchTab({
								url: '/pages/shoper/list'
							})
						}, 1000)
					} else {
						that.loading = false
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.ys {
		.inputbox {
			width: 96%;
			margin: 0px auto;
		}

		.form {
			padding-bottom: 15px;
			background: #fff;
			color: #000;
		}

		.btn {
			button {
				color: #fff;
				font-size: 16px;
				letter-spacing: 1px;
				margin: 30px auto;
				width: 96%;
			}
		}
	}
</style>